﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusLib
{
    public partial class Fare_Rule
    {
        public static Fare_Rule ImportCSV(string line)
        {
            Fare_Rule fr = null;
            string[] fields = line.Split(',');

            if (fields[0] != "fare_id")
            {
                fr = new Fare_Rule();

                fr.fare_id = int.Parse(fields[0]);
                fr.route_id = fields[1] == "" ? null : (int?)int.Parse(fields[1]);
                fr.origin_id = int.Parse(fields[2]);
                fr.destination_id = int.Parse(fields[3]);
                fr.contains_id = fields[4] == "" ? null : (int?)int.Parse(fields[4]);

                BusLibDataContext.db.Fare_Rules.InsertOnSubmit(fr);
            }

            return fr;
        }
    }
}
